/* ===== 现代化CSS重置与规范化方案 ===== */

/* 1. 核心元素重置 */
:where(
  html,
  body,
  div,
  span,
  applet,
  object,
  iframe,
  h1,
  h2,
  h3,
  h4,
  h5,
  h6,
  p,
  blockquote,
  pre,
  a,
  abbr,
  acronym,
  address,
  big,
  cite,
  code,
  del,
  dfn,
  em,
  img,
  ins,
  kbd,
  q,
  s,
  samp,
  small,
  strike,
  strong,
  sub,
  sup,
  tt,
  var,
  b,
  u,
  i,
  center,
  dl,
  dt,
  dd,
  ol,
  ul,
  li,
  fieldset,
  form,
  label,
  legend,
  table,
  caption,
  tbody,
  tfoot,
  thead,
  tr,
  th,
  td,
  article,
  aside,
  canvas,
  details,
  embed,
  figure,
  figcaption,
  footer,
  header,
  hgroup,
  menu,
  nav,
  output,
  ruby,
  section,
  summary,
  time,
  mark,
  audio,
  video
) {
  margin: 0;
  padding: 0;
  border: 0;
  font: inherit;
  vertical-align: baseline;
}

/* HTML5元素显示设置 */
:where(
  article,
  aside,
  details,
  figcaption,
  figure,
  footer,
  header,
  hgroup,
  main,
  menu,
  nav,
  section
) {
  display: block;
}

/* 2. 盒模型与文档流优化 */
:where(html) {
  box-sizing: border-box;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  line-height: 1.15;
}

:where(*, ::before, ::after) {
  box-sizing: inherit;
  background-repeat: no-repeat;
}

/* 3. 主体与排版增强 */
:where(body) {
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* 4. 媒体元素处理 */
:where(img, picture, video, canvas, svg) {
  max-width: 100%;
  height: auto;
}

:where(img) {
  border-style: none;
}

:where(svg:not([fill])) {
  fill: currentColor;
}

/* 5. 交互与表单元素标准化 */
:where(button, input, select, textarea) {
  font: inherit;
  margin: 0;
}

:where(button, input) {
  overflow: visible;
}

:where(button, select) {
  text-transform: none;
}

:where(button, [type='button'], [type='reset'], [type='submit']) {
  -webkit-appearance: button;
  appearance: button;
  cursor: pointer;
}

:where(
  button::-moz-focus-inner,
  [type='button']::-moz-focus-inner,
  [type='reset']::-moz-focus-inner,
  [type='submit']::-moz-focus-inner
) {
  border-style: none;
  padding: 0;
}

:where(textarea) {
  overflow: auto;
  resize: vertical;
}

:where([type='checkbox'], [type='radio']) {
  box-sizing: border-box;
  padding: 0;
}

:where([type='search']) {
  -webkit-appearance: textfield;
  outline-offset: -2px;
}

:where([type='search']::-webkit-search-decoration) {
  -webkit-appearance: none;
}

/* 6. 文本级语义元素 */
:where(a) {
  background-color: transparent;
  text-decoration: none;
  color: inherit;
}

:where(abbr[title]) {
  text-decoration: underline dotted;
}

:where(b, strong) {
  font-weight: bolder;
}

:where(code, kbd, samp) {
  font-family: monospace, monospace;
  font-size: 1em;
}

:where(small) {
  font-size: 80%;
}

:where(sub, sup) {
  font-size: 75%;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
}

:where(sub) {
  bottom: -0.25em;
}

:where(sup) {
  top: -0.5em;
}

/* 7. 列表与表格 */
:where(ol, ul) {
  list-style: none;
}

:where(table) {
  border-collapse: collapse;
  border-spacing: 0;
}

/* 8. 引号与引用 */
:where(blockquote, q) {
  quotes: none;
}

:where(blockquote::before, blockquote::after, q::before, q::after) {
  content: none;
}

/* 9. 可访问性改进 */
:where(:focus-visible) {
  outline: 2px solid #007acc;
  outline-offset: 2px;
}

:where([aria-busy='true']) {
  cursor: progress;
}

:where([aria-disabled='true'], :disabled) {
  cursor: not-allowed;
  opacity: 0.7;
}

:where([hidden]) {
  display: none !important;
}

/* 10. 减少运动偏好 */
@media (prefers-reduced-motion: reduce) {
  :where(*, ::before, ::after) {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* 11. 打印优化 */
@media print {
  :where(*, ::before, ::after) {
    background: white !important;
    color: black !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }

  :where(a, a:visited) {
    text-decoration: underline;
  }

  :where(a[href]:after) {
    content: ' (' attr(href) ')';
  }

  :where(pre, blockquote) {
    border: 1px solid #999;
    page-break-inside: avoid;
  }

  :where(tr, img) {
    page-break-inside: avoid;
  }

  :where(p, h2, h3) {
    orphans: 3;
    widows: 3;
  }

  :where(h2, h3) {
    page-break-after: avoid;
  }
}
